<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<%@ page import="com.pptree.service.*" %>
<%@ page import="com.pptree.service.impl.*" %>
<%@ page import="com.pptree.vo.*" %>


<%
	request.setCharacterEncoding("UTF-8");
	String username = request.getParameter("loginId");
	String password = request.getParameter("loginPwd");
	Boolean rememberMe = Boolean.valueOf(request.getParameter("rememberMe"));
	System.out.println("rememberMe --->" + rememberMe);
	UserService userService = new UserServiceImpl();
	User user = userService.login(username, password);
	System.out.println(user);
	if(user != null){
		session.setAttribute("CurrentUser", user);
		
		String userInfo = user.getUsername() + "_" + user.getPassword();
		Cookie cookie = new Cookie("userCookie",userInfo);
		if(rememberMe.booleanValue()){
			
			cookie.setMaxAge(10 * 24 * 60 * 60); //设置Cookie过期时间为10天过期——持久性Cookie(将Cookie信息保存磁盘上。)
			
		}
		else{
			cookie.setMaxAge(-1); //设置Cookie立即过期——会话Cookie(存活在浏览器进程中。)
		}
		//写入Cookie
		response.addCookie(cookie);
		System.out.println("userType ---------------->" + user.getUserType());
		if(user.getUserType() == 0){
			System.out.println("ok!!");
			response.sendRedirect("admin/manager.jsp");
		}
		else
		{
			response.sendRedirect("index.jsp");
		}
	}
	else{
		request.setAttribute("ErrorMsg", "登录名或密码错误！");
		request.getRequestDispatcher("login.jsp").forward(request, response);
	}
	
%>
